package com.xusiyan08.repository;

import com.xusiyan08.entity.Favorite;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface FavoriteRepository extends JpaRepository<Favorite, Long> {
    List<Favorite> findByUserId(Long userId);

    @Query("SELECT f FROM Favorite f JOIN Item i ON f.itemId = i.itemId WHERE f.userId = :userId")
    List<Favorite> findUserFavoritesWithItems(@Param("userId") Long userId);

    void deleteByUserIdAndItemId(Long userId, Long itemId);

    Optional<Favorite> findByUserIdAndItemId(Long userId, Long itemId);

    boolean existsByUserIdAndItemId(Long userId, Long itemId);
}